package com.sunday.android.fangdaifu.bukong.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sunday.android.fangdaifu.bukong.R;
import com.sunday.android.fangdaifu.bukong.activity.index.IndexItemActivity;
import com.sunday.android.fangdaifu.bukong.entity.IndexProject;
import com.sunday.android.fangdaifu.bukong.entity.IndexTop;
import com.sunday.android.fangdaifu.bukong.entity.ProjectListItem;
import com.sunday.android.fangdaifu.bukong.utils.noticeview.NoticeShowUtils;
import com.sunday.android.fangdaifu.bukong.utils.noticeview.NoticeView;
import com.sunday.android.fangdaifu.bukong.utils.pie.HollowPieNewChart;
import com.sunday.android.fangdaifu.bukong.utils.pie.PieData;
import com.sunday.android.fangdaifu.bukong.utils.stickyheadersrecyclerview.StickyRecyclerHeadersAdapter;
import com.sunday.common.utils.PixUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ProjectListWithHeadersAdapter extends RecyclerView.Adapter implements StickyRecyclerHeadersAdapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<ProjectListItem.ListBean> projectList = new ArrayList<>();//报警项目列表'

    public ProjectListWithHeadersAdapter(Context mContext, List<ProjectListItem.ListBean> projectList) {
        this.mContext = mContext;
        this.projectList = projectList;
        setHasStableIds(true);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.index_project_view_item, parent, false);
        return new ItemHolder(view);
    }

    //单个内容
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ItemHolder itemHolder = (ItemHolder) holder;
        final ProjectListItem.ListBean item = projectList.get(position);
        itemHolder.tvName.setText(item.getName());
        itemHolder.lMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (selectItem!=null){
                    selectItem.selectItem(position,item);
                }
            }
        });
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public long getHeaderId(int position) {
        return projectList.get(position).getEnStr().charAt(0);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.index_project_view_header, parent, false);
        return new HeaderHolder(view);
    }

    //头部内容
    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
        HeaderHolder headerHolder = (HeaderHolder) holder;
        ProjectListItem.ListBean item = projectList.get(position);
        headerHolder.tvHeader.setText(item.getEnStr());
    }

    @Override
    public int getItemCount() {
        return projectList.size();
    }

    public interface SelectItem{
        void selectItem(int position, ProjectListItem.ListBean bean);
    }
    private SelectItem selectItem;
    public void setSelectItem(SelectItem selectItem){
        this.selectItem = selectItem;
    }

    //item view
    class ItemHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tvName)
        TextView tvName;
        @Bind(R.id.lMain)
        View lMain;
        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    //header view
    class HeaderHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tvHeader)
        TextView tvHeader;
        public HeaderHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}